Ext.define('AmpleHarvest.objects.hierarchydata.cHierarchyData',
		{
			extend			: 'Ext.tree.Panel',
			alias			: 'widget.ampleharvest-objects-hierarchydata-chierarchydata',
			title			: 'Structured Data',
			requires		:
			[
				'Ext.data.TreeStore'
			],
			collapsible		: true,
			collapseFirst	: true,
			iconCls			: 'toolbar-article-enhancement-hierarchy',
			border			: 0,
			store			: Ext.create('Ext.data.TreeStore',
					{
						root	:
						{
							expanded	: false,
							children	: []
						}
					}),
			border			: 0,
			rootVisible		: false,

			initComponent	: function()
			{
				var obj_This = this;

				this.tools =
				[
						{
							type	: "expand",
							handler	: this.expandAll,
							tooltipType : "title",
							tooltip	: "Expand",
							scope	: this
						},
						{
							type	: "collapse",
							handler	: this.collapseAll,
							scope	: this
						}
				];

				this.callParent();
			},

			add_JsonObject	: function(JsonObject)
			{
				this.ts_construct(JsonObject, new Array(), this.getStore()
								.getRootNode());
			},

			ts_construct	: function(JsonObject, storeArray, rootParent)
			{
				this.itemCount = 0;
				if (JsonObject.data)
				{
					for (var value in JsonObject.data)
					{
						
						var partenNode = rootParent;
						
						var path = JsonObject.data[value].name
								.split(JsonObject.separator);
							
						var length = path.length;
						
						var myName = '';
						for (var i = 0; i <= length; i++)
						{
							myName = myName+"_"+path[i];
							if (i < length)
							{
								if (existNode = partenNode.findChild("xPath",
										myName, true
								))
								{
									partenNode = existNode;
									continue;
								}
										
								partenNode = this.ts_add(partenNode, path[i],
										"group",
										'',
										myName	
								);
							}
							else if (i == length)
							{
								this.ts_add(partenNode,
										JsonObject.data[value].value, 
										"leaf",
										JsonObject.data[value],
										myName
								);
							}
						}
						this.itemCount++;
					}
				}
				this.collapseAll();
			},

			ts_add			: function(node_Obj, add_Obj, type, obj_Node, xPath_Str)
			{
				if (type == 'group')
				{
					var appended_node = node_Obj.appendChild(
							{
								text		: add_Obj,
								xPath		: xPath_Str,
								expanded	: true,
								children	: []
							});
					return appended_node;
				}
				else
				{
					obj_Node.text = add_Obj;
					obj_Node.leaf = true;

					node_Obj.appendChild(obj_Node);
				}
			},

			hasData			: function()
			{
				if (!this.itemCount)
				{
					return false;
				}
				if (this.itemCount < 1)
				{
					return false;
				}
				this.setTitle(this.title+' ('+this.itemCount+')');
				return true;
			}
		});
